package com.aitaoxue.palx.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

import com.aitaoxue.palx.R;
import com.aitaoxue.palx.api.ApiHttpClient;
import com.aitaoxue.palx.base.ListBaseAdapter;
import com.aitaoxue.palx.bean.Teacher;
import com.aitaoxue.palx.widget.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class SearchAdapter extends ListBaseAdapter {

	@Override
	protected View getRealView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null || convertView.getTag() == null) {
			convertView = getLayoutInflater(parent.getContext()).inflate(
					R.layout.list_cell_search, null);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Teacher teacher = (Teacher) _data.get(position);

		viewHolder.name.setText(teacher.getProd_name());
		viewHolder.course.setText(teacher.getGood_kind_name());
		viewHolder.exper.setText("经验:" + teacher.getProd_experience() + "个月");
		viewHolder.school.setText("学校:" + teacher.getProd_company());
		viewHolder.goodAt.setText("擅长科目:" + teacher.getGood_kind_name());
		viewHolder.money.setText("￥" + teacher.getGood_price() + "元/课时");

		ImageLoader.getInstance().displayImage(
				ApiHttpClient.HEADER_PREFIX + teacher.getProd_head_thumb(),
				viewHolder.headImg);

		switch (teacher.getProd_sex()) {
		case "男":
			viewHolder.sex.setImageResource(R.drawable.male);
			break;
		case "女":
			viewHolder.sex.setImageResource(R.drawable.female);
			break;
		default:
			break;
		}

		return convertView;
	}

	static class ViewHolder {
		@InjectView(R.id.head_img)
		CircleImageView headImg;
		@InjectView(R.id.sex)
		ImageView sex;
		@InjectView(R.id.name)
		TextView name;
		@InjectView(R.id.course)
		TextView course;
		@InjectView(R.id.exper)
		TextView exper;
		@InjectView(R.id.school)
		TextView school;
		@InjectView(R.id.good_at)
		TextView goodAt;
		@InjectView(R.id.money)
		TextView money;

		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}

	}
}
